package com.gimi.cloud.jimi.manage.consumer.service.order.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.exception.MsgException;
import com.gimi.cloud.jimi.common.utils.EntityVerification;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.common.utils.reqhead.Verification;
import com.gimi.cloud.jimi.dto.order.OrderLogisticsDTO;
import com.gimi.cloud.jimi.manage.consumer.feign.OrderFeignService;
import com.gimi.cloud.jimi.manage.consumer.service.order.OrderLogisticsService;
@Service
public class OrderLogisticsServiceImpl implements OrderLogisticsService {
	@Autowired
	private OrderFeignService orderFeignService;
	
	private static Logger logger = LoggerFactory.getLogger(OrderLogisticsServiceImpl.class);
	
	
	@Override
	public Response deleteOrderLogistics(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws MsgException {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		OrderLogisticsDTO dto = JsonUtil.jsonToBean(requestBody,OrderLogisticsDTO.class);
        Verification verification = EntityVerification.checkEntity(dto);
        if(!verification.getCheckResult()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR,verification.getMsg());
            return resp;
        }else{
            return orderFeignService.deleteOrderLogistics(dto);
        }
	}

	@Override
	public Response getSingleOrderLogistics(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws MsgException {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		OrderLogisticsDTO dto = JsonUtil.jsonToBean(requestBody,OrderLogisticsDTO.class);
		Verification verification = EntityVerification.checkEntity(dto);
		if(!verification.getCheckResult()){
			Response resp = new Response();
			resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR,verification.getMsg());
			return resp;
		}else{
			return orderFeignService.getSingleOrderLogistics(dto);
		}
	}

	@Override
	public Response updateOrderLogistics(@RequestBody String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws MsgException {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		OrderLogisticsDTO dto = JsonUtil.jsonToBean(requestBody,OrderLogisticsDTO.class);
		Verification verification = EntityVerification.checkEntity(dto);
		if(!verification.getCheckResult()){
			Response resp = new Response();
			resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR,verification.getMsg());
			return resp;
		}else{
			return orderFeignService.updateOrderLogistics(dto);
		}
	}

}
